package org.ftc.dao;

import java.util.List;

import org.ftc.domain.CodeUnit;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.springframework.stereotype.Repository;

@Repository
public class CodeUnitDao extends CurrentDao <CodeUnit, String> {

	@Override
	public CodeUnit load(String id) {
		return super.load(id);
	}

	@Override
	public CodeUnit get(String id) {
		return super.get(id);
	}

	@Override
	public synchronized boolean save(CodeUnit entity) {
		return super.save(entity);
	}

	@Override
	public synchronized boolean saveOrUpdate(CodeUnit entity) {
		return super.saveOrUpdate(entity);
	}

	@Override
	public synchronized boolean update(CodeUnit entity) {
		return super.update(entity);
	}

	@Override
	public synchronized boolean delete(CodeUnit entity) {
		return super.delete(entity);
	}

	@Override
	public synchronized boolean delete(String id) {
		return super.delete(id);
	}
	
	@Override
	public List<CodeUnit> findPage(int offset, int pageSize) {
		return super.findPage(offset, pageSize);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CodeUnit> findAll() {
		try{	
			Criteria criteria = getSession().createCriteria(CodeUnit.class);
			criteria.setCacheable(true);
			criteria.addOrder(Order.asc("code"));
			criteria.addOrder(Order.asc("sort"));
			List<CodeUnit> list = (List<CodeUnit>) criteria.list();
			return list; 
		}catch( Exception e ){
			e.printStackTrace();
			getLog().error(e.toString());
			return null;
		}
	}

	@Override
	public long countAll() {
		return super.countAll();
	}


}
